package com.hh.vietnameseproject.logic.interceptor

import android.os.Build
import android.util.Log
import okhttp3.Interceptor
import okhttp3.Response

class HeaderInterceptor:Interceptor {
    companion object{
        var cookies:String? = null
    }

    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request();
        val  builder = request.newBuilder();
        if(cookies!=null) {
            builder.addHeader("Cookie", cookies)
            if (Build.VERSION.SDK != null && Build.VERSION.SDK_INT > 13) {
                builder.addHeader("Connection", "close");
            }
        }
        else{
            Log.e("Cookie","Cookie not found");
        }
        return chain.proceed(builder.build());
    }
}